package com.zhisuo.apicenter.service.imp;


import com.zhisuo.apicenter.model.RubbishOrder;
import com.zhisuo.apicenter.model.RubbishOrderRowMapper;
import com.zhisuo.apicenter.service.RubbishEventService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RubbishEventServiceImp extends BaseServiceImp implements RubbishEventService {


    @Override
    public String getCarIdByParkAreaId(int parkareaid) {
        String sql="select carid from parkarea_car where parkareaid=?";
        return queryString(sql,new Object[]{parkareaid});
    }

    @Override
    public void insertNewRubbishOrder(String receiptuserid, String buildid, String receiptuserorderstarttime, String receiptuserorderendtime, String carid, Integer boxid, String boxcode, String buildname,Integer parkareaid,String buildcode) {
        String sql="insert into box_rubbish_order(carid,boxid,boxcode,receiptuserid,receiptuser_confirmtime,create_time,status,receiptuserbuildname,receiptuserbuildid,receiptuseraddressid,receiptuserorderstarttime,receiptuserorderendtime,receiptuserparkareaid,receiptuseraddresscode)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        update(sql,new Object[]{carid,boxid,boxcode,receiptuserid,new Date(),new Date(),0,buildname,buildid,0,receiptuserorderstarttime,receiptuserorderendtime,parkareaid,buildcode});

    }

    @Override
    public RubbishOrder getRubbishOrderByUserIdAndDay(String userid) {
        String sql="select * from box_rubbish_order where receiptuserid=? and  now()>=receiptuserorderstarttime and now()<=receiptuserorderendtime";

        return getEntry(sql,new RubbishOrderRowMapper(),new Object[]{userid});
    }

    @Override
    public List<RubbishOrder> getRubbishOrderByParkAreaId(String parkareaid,String nowdate) {
        String sql="select * from box_rubbish_order where receiptuserparkareaid=? and receiptuserorderstarttime>=? order by receiptuserorderstarttime asc";
        return getEntryList(sql,new RubbishOrderRowMapper(),new Object[]{parkareaid,nowdate});
    }
}
